package controllers

import (
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
	"BeiFengGoProj/GitRepo/BeiFengGoProj/webproj/hello/models"
)

type MainController struct {
	beego.Controller
}

func (c *MainController) Get() {
	//c.Data["Website"] = "beego.me"
	//c.Data["Email"] = "astaxie@gmail.com"
	c.TplName = "register.html"
}

func (c *MainController) Register() {

	//获取用户名密码
	userName := c.GetString("userName")
	pwd := c.GetString("password")
	//2.对数据进行校验
	if userName=="" || pwd == ""{
		beego.Info("数据不能为空")
		c.Redirect("/reg",302)
		return
	}
	//3.插入数据库
	o :=orm.NewOrm()

	user := models.User{}
	user.Name = userName
	user.Pwd = pwd

	_,err := o.Insert(&user) //一定是地址
	if err != nil{
		beego.Info("插入数据失败")
		c.Redirect("/reg",302)
		return
	}
	c.Ctx.WriteString("插入成功")
	//c.Redirect("/login",302)
}
